#ifndef HTTPCLIENTCONNECTION_H
#define HTTPCLIENTCONNECTION_H

#include "messageheader.h"
#include "HTTPresponse.h"
#include "httputil.h"
#include <string>
using std::string;
using HTTPUtil::HTTPMethod;

// hints: This class is not thread-safe
// take care of it.
class HTTPClientConnection {
public:

    HTTPClientConnection();
    ~HTTPClientConnection();
    // Send a request to connectted host,
    // This method wiil block until
    // the whole response is recved.
    // if connection has not created yet,
    // it will try to do it sliently.
    HTTPResponse request(HTTPMethod method, const MessageHeader& headers, const string& path);
    // if alreadly connected, return true.
    // otherwise, try to connect the server
    // according to current settings and
    // return whether it successes.
    bool connect();
    void disconnect();
    void setHost(const string& host);
    void setPort(const int port);

    const string getHost() const {
        return m_host;
    }
    int getPort() const {
        return m_port;
    }
private:
    string m_host;
    int m_port;
    int m_sockfd;
    static const string USER_AGENT;

    const string requestLine(HTTPMethod method, const string& path) const;
    int createSocket() const;

};
#endif
